/* 
    <provides OS-like functionality using a time-triggered scheduler>
    Copyright (C) <2012>  <Jonathan D. Armstrong> <jonathan.armstrong AT mavs.uta.edu>

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

/**
 * @file   state-machine.h
 * @Author Jonathan D. Armstrong (jonathan.armstrong@mavs.uta.edu)
 * @date   December, 2012
 * @brief  Example of how to use a state machine in a task within
 *         the time-triggered architecture.
 *
 * These state machines avoid using the traditional SWITCH statement approach.
 */
 
#ifndef STATE_MACHINE_H
#define STATE_MACHINE_H

/* available state machine states - these must be sequentially indexed */
typedef enum state_t
{
    STATE1 = 0,
    STATE2,
    STATE3,
}state_t;

/* 
    state structure links together state with function pointer
*/
typedef struct state_table_t
{
    state_t state;                      // state associated with function pointer (see enum above)
    state_t (*functionPtr)(uint8_t);    // allows calling of a function associated with a particular state
    uint32_t period;                    // FIXME: implement this later to allow delay of task states
}state_table_t;

/* FIXME: consider NOT including function prototypes for individual state functions
   as these should not be called outside of the main state function
   (i.e., in this case length_task();) - we must here in order to initialize
   state table at beginning of state-machine.c
*/

state_t state1_function(uint8_t);
state_t state2_function(uint8_t);
state_t state3_function(uint8_t);

/* function prototypes*/
uint8_t lengthy_task(uint8_t);

#endif //STATE-MACHINE_H